import request from "@/utils/request";

const EQUITY_MALL_BASE_URL = "/platform/mall";

const EquityMallAPI = {
  /***
   *
   * 产品分类
   *
   *
   */
  // 获取产品分类根节点
  getProductCategoryRoot() {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/category/getRoot`,
      method: "get",
    });
  },
  // 分页查询产品分类
  getProductCategoryPage(data: { pageNum: number; pageSize: number }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/category/page`,
      method: "get",
      params: data,
    });
  },
  // 新增产品分类
  addProductCategory(data: { id: number; parentId: number; name: string }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/category/add`,
      method: "post",
      data,
    });
  },
  // 编辑产品分类
  updateProductCategoryById(data: { id: number; parentId: number; name: string }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/category/updateById`,
      method: "put",
      data,
    });
  },
  // 查询产品分类
  getProductCategoryById(id: number) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/category/getSelfAndSubById`,
      method: "get",
      params: { id },
    });
  },
  // 删除产品分类
  deleteProductCategoryById(id: number) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/category/deleteByIds`,
      method: "post",
      data: { ids: [id] },
    });
  },
  /****
   *
   * 商品属性
   *
   */
  // 获取所有商品属性
  getAllProductProperty() {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/property/getAll`,
      method: "get",
    });
  },

  // 新增商品规格标签
  addProductProperty(data: { name: string; tags: string }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/property/add`,
      method: "post",
      data,
    });
  },
  // 编辑商品规格标签
  editProductProperty(data: { id: number; name: string; tags: string }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/property/updateById`,
      method: "post",
      data,
    });
  },
  // 分页查询商品规格标签
  getProductSpecTagPage(data: { pageNum: number; pageSize: number }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/specTag/page`,
      method: "get",
      params: data,
    });
  },
  // 删除商品规格标签
  deleteProductProperty(id: number) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/property/deleteByIds`,
      method: "post",
      data: { ids: [id] },
    });
  },
  /***
   *  商品规格
   *
   */
  // 根据商品规格标签id查询商品规格
  getProductSpecByTagIds(data: any) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/spec/getByTagIds`,
      method: "post",
      data: data,
    });
  },

  // 新增商品规格标签
  addProductSpec(data: { name: string; specTagId: number }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/spec/add`,
      method: "post",
      data,
    });
  },
  // 删除商品规格
  deleteProductSpec(id: number) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/spec/deleteByIds`,
      method: "post",
      data: { ids: [id] },
    });
  },
  // 编辑商品规格
  editProductSpec(data: { id: number; name: string; specTagId: number }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/spec/updateById`,
      method: "post",
      data,
    });
  },
  /****
   *
   * 新增商品
   *
   */
  addProduct(data: any) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/add`,
      method: "post",
      data,
    });
  },
  // 编辑商品
  editProduct(data: any) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/updateById`,
      method: "post",
      data,
    });
  },
  // 分页查询商品
  getProductPage(data: { pageNum: number; pageSize: number }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/page`,
      method: "get",
      params: data,
    });
  },
  // 根据id查询商品
  getProductDetailById(id: number) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/getDetailById`,
      method: "get",
      params: { id },
    });
  },
  // 删除商品
  deleteProductByIds(data: { ids: number[] }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/deleteByIds`,
      method: "post",
      data,
    });
  },
  // 上架商品
  shelfProduct(data: { id: number; shelfType: number; shelfTime: string }) {
    return request({
      url: `${EQUITY_MALL_BASE_URL}/product/doShelf`, // 上架
      method: "post",
      data,
    });
  },
};
export default EquityMallAPI;
